package com.ykdl.member.views;

import java.util.List;

import com.ykdl.member.kid.R;
import com.ykdl.member.kid.models.TopicBean;
import com.ykdl.member.kid.util.MobileUtils;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

public class FreakyChatChild extends RelativeLayout {
	
	private Context context;
	private LinearLayout ll_freaky_chat_child_item;
	private List<TopicBean> topics;
	public FreakyChatChild(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public FreakyChatChild(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public FreakyChatChild(Context context) {
		super(context);
	}
	public void setData(List<TopicBean> topics){
		this.topics = topics;
	}
	public void initView(Context context){
		this.context = context;
		LayoutInflater.from(context).inflate(R.layout.freaky_chat_child_view, this, true);
		ll_freaky_chat_child_item = (LinearLayout) findViewById(R.id.gv_freaky_chat_child);
		
		/**设置适配**/
		int screenWidth = MobileUtils.getScreenWidthIntPx();
		int view_item_width = (screenWidth - MobileUtils.dpToPx(36)) / 2;

		if(topics != null && topics.size() > 0){
			RelativeLayout relativeLayout = null;
			RelativeLayout.LayoutParams params;
			View view = null;
			for(int i = 0 ;i < topics.size(); i++){
				FreakyChatChildItem item = new FreakyChatChildItem(context, topics.get(i));
//				RelativeLayout  item = item2.init();
				LayoutParams item_params = new LayoutParams(view_item_width, android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
				
				if(i % 2 == 0){ //偶数
					relativeLayout = new RelativeLayout(context);
					params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
					params.topMargin = MobileUtils.dpToPx(100);
					relativeLayout.setLayoutParams(params);
					
					item_params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
					relativeLayout.addView(item, item_params);
					//添加分割线条
					view = new View(context);
					android.widget.RelativeLayout.LayoutParams view_params = new LayoutParams(LayoutParams.FILL_PARENT, MobileUtils.dpToPx(10));
					view.setLayoutParams(view_params);
					view.setBackgroundColor(getResources().getColor(R.color.baby_cang_zi));
				}else{
					item_params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
					relativeLayout.addView(item, item_params);
					
					ll_freaky_chat_child_item.addView(relativeLayout);
					ll_freaky_chat_child_item.addView(view);
					
					relativeLayout = null;
					params = null;
					view = null;
				}
			}
			
			if(relativeLayout != null){
				ll_freaky_chat_child_item.addView(relativeLayout);
				relativeLayout = null;
				params = null;
			}
		}

	}
	
	
	

}
